package com.strongdigit.ioc.beanannotation.javabased;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

@Configuration
@ImportResource("classpath:config.xml")
public class StoreConfig {

    @Value("${url}")
    private String url;
    @Value("${username}")
    private String username;
    @Value("${password}")
    private String password;

    @Bean
    public DataSourceManager dataSourceManager() {
        return new DataSourceManager(url, username, password);
    }





//    @Bean(name = "stringstore", initMethod = "init", destroyMethod = "destory")
//    @Scope
//    public Store getStringStore() {
//
//        return new StringStore();
//    }

    //泛型注入，在sp4.0引入的
   @Autowired
    private Store<String> s1;

    @Autowired
    private Store<Integer> s2;


    @Bean(name="stringStoreTest")
    public StringStore stringStoreTest(){
        if(null!=s1)
        {
            System.out.println(s1.getClass().getName());
        }
        else {
            System.out.println("s1 is null");
        }
        if(null!=s2)
        {
            System.out.println(s2.getClass().getName());
        }
        else {
            System.out.println("s2 is null");
        }

        return new StringStore();
    }

    @Bean
    public IntStore intStoreTest(){
        return new IntStore();
    }


}
